#ifndef DSPSIMULATOR_ELF32LOADER_H
#define DSPSIMULATOR_ELF32LOADER_H

#include <simulator/elf/elfLoader.h>

class ELF32Loader : public ELFLoader {
public:
    ELF32Loader() = default;

    ~ELF32Loader() override = default;

    u64 loadELFProgramIntoMemory(const char *elfFilePath, std::shared_ptr<Memory> memory) override;

protected:
    void load_phdr(Elf32_Phdr *phdr, Elf32_Ehdr *ehdr, u32 i, std::ifstream &elfFile) override;

    void
    loadSegmentIntoMemory(u64 index, std::shared_ptr<Memory> memory, Elf32_Phdr *phdr, std::ifstream &elfFile) override;

private:
    /**
     * 根据标志位flag获取段的读、写、执行权限
     * @param flag 标志位
     * @param canRead 如果段可读，设置该标志位为true，否则为false
     * @param canWrite 如果段可写，设置该标志位为true，否则为false
     * @param canExecute 如果段可执行，设置该标志位为true，否则为false
     */
    static void getSegmentFlag(u32 flag, bool &canRead, bool &canWrite, bool &canExecute);
};

#endif //DSPSIMULATOR_ELF32LOADER_H
